<template>
  <el-menu
    background-color="#333744"
    text-color="#fff"
    active-text-color="#409BFF"
    unique-opened
    :collapse="isCollapse"
    :collapse-transition="false"
    :router="true"
    :default-active="activePath"
  >
    <!-- 一级菜单 -->
    <el-submenu v-for="item in menuList" :key="item.id" :index="item.id + ''">
      <!-- 一级菜单模板区 -->
      <template slot="title">
        <!-- 图标 -->
        <i :class="iconObj[item.id]"></i>
        <!-- 文本 -->
        <span>{{ item.authName }}</span>
      </template>

      <!-- 二级菜单 -->
      <el-menu-item
        v-for="subItem in item.children"
        :key="subItem.id"
        :index="'/' + subItem.path"
        @click="saveNavState('/' + subItem.path)"
      >
        <template slot="title">
          <!-- 图标 -->
          <i class="el-icon-menu"></i>
          <!-- 文本 -->
          <span>{{ subItem.authName }}</span>
        </template>
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  name: 'HomeAside',
  props: {
    menuList: {
      type: Array,
      default() {
        return []
      },
    },
    isCollapse: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      iconObj: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao',
      },
      activePath: '',
    }
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    },
  },
}
</script>

<style lang="less" scoped>
.iconfont {
  margin-right: 10px;
}
.el-menu {
  border-right: none;
}
</style>>
